// gjw/pages/member/index.js

const app= getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
  
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
  // 获取平台客服电话
    var that = this
		that.setData({
			userInfo: wx.getStorageSync('userInfo')
		})
    app.route(this)
    app.util.request({
      url: 'entry/wxapp/sertel',
      success: function (res) {
        
        that.setData({
          phone:res.data.res
        })
      }
    })
    // that.getdata()
    that.identy()
    that.first()
		that.shottopay()
    that.getAll()
		that.marktopay()
    that.getOrder()

  },

  // tabbar.js
  tabbar: function (e) {
    var that = this
    var url = e.currentTarget.dataset.url
    wx.reLaunch({
      url: url,
    })
  },

  // 判断身份
  identy: function (e) {
    var that = this
		var openid = wx.getStorageSync("openid")
    app.util.request({
      url: 'entry/wxapp/Iscustomers',
      data: { openid: openid },
      success: function (res) {
        
        // if (res.data.code == 200 || res.data.code == 204) {
        //   // 认证审核通过
        //   that.getdata()
        // } else{    //商家审核未通过  用户
        //   // 获取用户信息
          app.util.request({
            url:'entry/wxapp/Userinfo',
            data:{
              openid:openid,
            },
            success:function(res){
              
              that.setData({
                user:res.data.res
              })
            }
          })
        // }
      }
    })
  },

  // 微拍进行中数据
  first: function (e) {
    var that = this
    var openid = wx.getStorageSync('openid')
    app.util.request({
      url: 'entry/wxapp/Myshoting',
      data: { openid: openid },
      success: function (res) {
        
        if (res.data.code == 200) {
          var array = res.data.res
          for (let i in array) {
            var myfee = Number(array[i].fee)
            var max = Number(array[i].max)
            if (myfee < max) {
              array[i].arr = '出局'
            } else if (myfee >= max) {
              array[i].arr = '领先'
            }

          }
          that.setData({
            first: res.data.res
          })


        } else if (res.data.code == 500) {
          that.setData({
            first: [],
          })
        }
      }
    })
  },
	// 待付款
	shottopay: function (e) {
		var that = this
		var openid = wx.getStorageSync('openid')
		app.util.request({
			url: 'entry/wxapp/Myshottopay',
			data: {
				openid: openid
			},
			success: function (res) {
				
				if (res.data.code == 500) {
					that.setData({
						shottopaylist: []
					})
				} else if (res.data.code == 200) {
					var list = res.data.res
					for (let i in list) {
						if (list[i].img != null) {
							list[i].img = list[i].img.split(',')
							that.setData({
								shottopaylist: list
							})
						} else {
							that.setData({
								shottopaylist: list
							})
						}
					}
				}
			}
		})
	}, 


  // 集市进行中数据
  getAll: function (e) {
    var that = this
    var openid = wx.getStorageSync('openid')
    app.util.request({
      url: 'entry/wxapp/Mymarketing',
      data: { openid: openid },
      success: function (res) {
        if (res.data.code == 200) {
          var array = res.data.res
          for (let i in array) {
            array[i].img = array[i].img.split(',')
          }
          that.setData({
            jishi: array
          })
        } else if (res.data.code == 500) {
          that.setData({
            jishi: [],
          })
        }
      }
    })
  },
	marktopay: function (e) {
		var that = this
		var openid = wx.getStorageSync('openid')
		app.util.request({
			url: 'entry/wxapp/Mymarkettopays',
			data: {
				openid: openid
			},
			success: function (res) {
				console.log(res)
				if (res.data.code == 500) {
					that.setData({
						marktopaylist: []
					})
				} else if (res.data.code == 200) {
					var array = res.data.res
					for (let i in array) {
						if (array[i].img != null) {
							array[i].img = array[i].img.split(',')
							
						}
					}
					that.setData({
						marktopaylist: array
					})
				}
			}
		})
	},

  // 全部订单
  getOrder: function (e) {
    var that = this
    var page = that.data.page
    var openid = wx.getStorageSync('openid')
    app.util.request({
      url: 'entry/wxapp/Personordersall',
      data: {
        openid: openid, page: page
      },
      success: function (res) {
        if (res.data.code == 500) {
          that.setData({
            allList: []
          })
        } else if (res.data.code == 200) {
          // for (let i in res.data.res) {
          //   res.data.res[i].img = res.data.res[i].img.split(',')
          // }
          that.setData({
            allList: res.data.res
          })
        }
      }
    })
  },


  // 获取资料
  getdata: function (e) {
    var that = this
    var openid = wx.getStorageSync('openid')
    app.util.request({
      url: 'entry/wxapp/Cusperson',
      data: {
        openid: openid
      },
      success: function (res) {
        
        var arry = res.data.res
        // arry.cardimg = arry.cardimg.split(',')
        that.setData({
          info: arry
        })
      }
    })
  },
  
  // 拨打客服电话
  call:function(e){
    var phone=this.data.phone
    wx.makePhoneCall({
      phoneNumber: phone //仅为示例，并非真实的电话号码
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
  
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
  
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
  
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
  
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
  
  }
})